package com.rui.study.algorithm.L_深入拆解JVM_逃逸分析;

import java.util.ArrayList;
import java.util.function.Consumer;

/**
 * @program: study
 * @description: -XX:+PrintGC -XX:-DoEscapeAnalysis（关闭逃逸分析，默认是开启的）
 * @author: Yaowr
 * @create: 2018-12-21 11:08
 **/
public class EscapeTest {

    public static void foreach(ArrayList<Object> list, Consumer<Object> f) {
        for (Object o : list) {
            f.accept(o);
        }
    }

    public static void main(String[] args) {
        ArrayList list = new ArrayList(100);
        for (int i = 0; i < list.size(); i++) {
            list.add(i);
        }

        for (int i = 0; i <= 400_000_000; i++) {
            foreach(list, obj -> {});
        }
    }
}
